import Page
from Page import Map
from Base.Base import Base
from selenium.webdriver.common.by import By


class MapRouteSelectPage(Base):
    """
    路线选择界面

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.route_home_btn = (By.XPATH, Map.RESOURCE_ID.format("rl_navigation_home"))

        # 左侧的返回键
        self.route_back_btn = (By.XPATH, Map.RESOURCE_ID.format('rl_navigation_back'))

        # 拥堵按钮
        self.route_congestion_btn = (By.XPATH, Map.RESOURCE_ID.format("tv_routeplan_prefer"))

        # 路线优势
        self.route_path_advantage_text = (By.XPATH, Map.path_advantage_text.format(""))

        # 路线时间
        self.route_time_text = (By.XPATH, Map.route_time_text.format(""))

        # 公里数
        self.route_kilometers_text = (By.XPATH, Map.kilometers_text.format(""))

        # 红绿灯个数
        self.route_traffic_lights_text = (By.XPATH, Map.traffic_lights_text.format(""))

        # 更多按钮
        self.route_more_btn = (By.XPATH, Map.more_btn.format(""))

        # 开始导航
        self.route_start_navigation_btn = (By.XPATH, Map.RESOURCE_ID.format("ll_start_navi"))

        # 路况按钮
        self.route_traffic_btn = (By.XPATH, Map.RESOURCE_ID.format("map_tmc"))

        # 放大按钮
        self.route_amplification_btn = (By.XPATH, Map.RESOURCE_ID.format("rl_zoom_in"))

        # 缩小按钮
        self.route_zoom_out_btn = (By.XPATH, Map.RESOURCE_ID.format("rl_zoom_out"))

        # 比例尺
        self.route_scale_img = (By.XPATH, Map.RESOURCE_ID.format("map_scale"))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.route_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.route_back_btn)

    def click_congestion(self):
        """
        点击拥堵按钮

        :return:None
        """
        self.click_element(self.route_congestion_btn)

    def get_path_advantage(self, index=2):
        """
        获得路线优势文案

        index 默认从2开始
        :return:获取元素
        """
        self.route_path_advantage_text = (By.XPATH, Map.path_advantage_text.format(index))
        return self.find_element_o(self.route_path_advantage_text)

    def get_time(self, index=2):
        """
        获得路线时间文案

        index 默认从2开始
        :return:获取元素
        """
        self.route_time_text = (By.XPATH, Map.route_time_text.format(index))
        return self.find_element_o(self.route_time_text)

    def get_kilometers(self, index=2):
        """
        获得公里数文案

        index 默认从2开始
        :return:获取元素
        """
        self.route_kilometers_text = (By.XPATH, Map.kilometers_text.format(index))
        return self.find_element_o(self.route_kilometers_text)

    def get_traffic_lights(self, index=2):
        """
        获得红绿灯数文案

        index 默认从2开始

        :return:获取元素
        """
        self.route_traffic_lights_text = (By.XPATH, Map.traffic_lights_text.format(""))
        return self.find_element_o(self.route_traffic_lights_text)

    def click_more(self, index=1):
        """
        点击更多按钮

        index 默认从2开始
        :return:None
        """
        self.route_more_btn = (By.XPATH, Map.more_btn.format(index))
        self.click_element(self.route_more_btn)

    def click_traffic(self):
        """
        点击路况按钮

        :return:None
        """
        self.click_element(self.route_traffic_btn)

    def click_amplification(self):
        """
        点击放大按钮

        :return:None
        """
        self.click_element(self.route_amplification_btn)

    def click_zoom_out(self):
        """
        点击缩小按钮

        :return:None
        """
        self.click_element(self.route_zoom_out_btn)

    def click_start_navigation(self):
        """
        点击开始导航

        :return:None
        """
        self.click_element(self.route_start_navigation_btn)

    def is_display_map_route(self):
        """
        查看是否进入路线选择首页

        :return:
        """
        return self.is_display(self.route_congestion_btn)
